package com.graph.test;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.graph.base.CommunityFinder;
import com.graph.base.VertexInterface;

public class Print {

	private CommunityFinder communityFinder = null;

	public Print(CommunityFinder communityFinder) {
		this.communityFinder = communityFinder;
	}
    public void setCommunityFinder(CommunityFinder communityFinder) throws Exception{
    	this.communityFinder = communityFinder;
    }
    public void printAllCommunity() throws Exception{
		List<Set<VertexInterface>> res = communityFinder.findAllCommunity();
		int i = 1;
		for (Set<VertexInterface> vertexInterfaces : res) {
			System.out.println("The number " + i + " community, the size of the community is " + vertexInterfaces.size());
			i ++;
			for (VertexInterface vertexInterface : vertexInterfaces) {
				System.out.print(vertexInterface.getName() + "、");
			}
			System.out.println();
	    }
		List<VertexInterface> boundaryVertices = communityFinder.getBoundaryVertices();
		if(boundaryVertices != null){
			System.out.println("The fuzzy vertex of community:");
			for (VertexInterface vertexInterface : boundaryVertices) {
				System.out.print(vertexInterface.getName() + "、");
			}
			System.out.println();
		}
    }

	public void initMatrix() throws Exception{
//		int matrix [][] = communityFinder.initMatrix();
//		System.out.println("相似矩阵：");
//		for(int i = 0;i < matrix.length;i ++){
//			for(int j = 0;j < matrix.length;j ++){
//				System.out.print(matrix[i][j] + " ");
//			}
//			System.out.println();
//		}
	}

	public void printCommunityByVertices(String aimName) throws Exception{
		Set<VertexInterface> res = new HashSet<VertexInterface>();
		res = communityFinder.findCommunityByVertices(aimName);
		System.out.print("'" + aimName+"'所属的社区节点(共" + res.size() + "个)：");
		for (VertexInterface vertexInterface : res) {
			System.out.print(vertexInterface.getName() + "、");
		}
		System.out.println();
    }
	
	public void printCommunityNMI(){
		System.out.println("NMI:" + communityFinder.getNMI());
	}

	public void printPrecision(){
		System.out.println("Precision:" + communityFinder.getPrecision());
	}
	public void printRecall(){
		System.out.println("Recall:" + communityFinder.getRecall());
	}
	public void printF1(){
		System.out.println("F1:" + communityFinder.getF1());
	}
}
